function e(e, n) {
    wx.showToast({
        title: e,
        icon: n
    });
}

function n(e, n) {
    var t = wx.getStorageSync("MAP_KEY");
    wx.request({
        url: "https://apis.map.qq.com/ws/geocoder/v1/?l&get_poi=1",
        data: {
            key: t,
            location: e
        },
        method: "GET",
        success: function(e) {
            n(e.data.result.address);
        },
        fail: function() {},
        complete: function() {}
    });
}

module.exports = {
    getLatLntHandler: function(e) {
        var t = null, a = null, o = null, r = null;
        wx.getLocation({ 
            type: "gcj02",
            success: function(s) {
                t = s.latitude, a = s.longitude, o = s.speed, r = s.accuracy, s.latitude, s.longitude, 
                n(t + "," + a, function(n) {
                    e({
                        title: n,
                        address: n,
                        location: {
                            lat: t,
                            lng: a
                        }
                    });
                });
            },
            fail: function() {},
            complete: function() {}
        });
    },
    intoPageHandler: function(e) {
        wx.navigateTo({
            url: e
        });
    },
    loginHandler: function(e) {
        wx.login({
            success: function(n) {
                n.code && (wx.setStorageSync("openId", n.code), wx.getUserProfile({
                    success: function(n) {
                        wx.setStorageSync("userMessage", {
                            avatar: n.userInfo.avatarUrl,
                            username: n.userInfo.nickName,
                            buttonText: "退出"
                        }), e({
                            avatar: n.userInfo.avatarUrl,
                            username: n.userInfo.nickName,
                            buttonText: "退出"
                        });
                    }
                }));
            },
            fail: function() {}
        });
    },
    payHandler: function(e) {
        wx.request({
            url: "https://cjapp.135k.com/index.php/api/Pay/rechargePay",
            method: "get",
            data: {
                uid: wx.getStorageSync("uid"),
                money: "0.01"
            },
            success: function(e, n) {
                console.log("res", e);
                var t = e.data.weixin.package.slice(10);
                wx.requestPayment({
                    timeStamp: "" + e.data.weixin.timeStamp,
                    nonceStr: "" + e.data.weixin.nonceStr,
                    package: "" + e.data.weixin.package,
                    signType: "MD5",
                    paySign: "" + e.data.weixin.paySign,
                    success: function(e) {
                        wx.showToast({
                            title: "支付成功",
                            duration: 1500,
                            success: function(e) {
                                console.log("eres", e), wx.request({
                                    url: "https://cjapp.135k.com/index.php/api/Pay/callback",
                                    method: "get",
                                    data: {
                                        uid: wx.getStorageSync("uid"),
                                        openid: wx.getStorageSync("openid"),
                                        pay_id: t
                                    },
                                    success: function(e) {
                                        console.log("resresres", e), n(e);
                                    }
                                });
                            }
                        });
                    },
                    fail: function(e) {}
                });
            }
        });
    },
    getPolyline: function(e) {
        var n = wx.getStorageSync("startAddress"), t = wx.getStorageSync("endAddress"), a = wx.getStorageSync("map_key");
        console.log("获取路线列表", t);
        var o = n.location.lat + "," + n.location.lng + "&to=" + t.location.lat + "," + t.location.lng ,p = '&policy=LEAST_DISTANCE';
        wx.request({
            url: "https://apis.map.qq.com/ws/direction/v1/driving/?from=" + o + "&key=" + a + p,
            header: {
                "content-type": "application/json"
            },
            success: function(n) {
                if (384 === n.data.status) ; else {
                    for (var t = n.data.result.routes[0].polyline, a = 2; a < t.length; a++) t[a] = t[a - 2] + t[a] / 1e6;
                    for (var o = [], r = 0; r < t.length; r += 2) o[o.length] = {
                        longitude: t[r + 1],
                        latitude: t[r]
                    };
                    e(o);
                }
            },
            fail: function() {}
        });
    },
    callPhoneHandler: function(e) {
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    showToast: e,
    showModal: function(n, t, a) {
        wx.showModal({
            title: n,
            content: t,
            success: function(e) {
                a(e.confirm);
            },
            fail: function() {
                e("网络出现问题，请重试", "none");
            }
        });
    },
    regTest: function(n, t, a) {
        return void 0 !== a ? !("" == n || !a.test(n)) || (e(t, "none"), !1) : "" != n && void 0 != n || (e(t, "none"), 
        !1);
    },
    bankTest: function(n) {
        for (var t = n.substr(n.length - 1, 1), a = n.substr(0, n.length - 1), o = new Array(), r = a.length - 1; r > -1; r--) o.push(a.substr(r, 1));
        for (var s = new Array(), i = new Array(), u = new Array(), c = 0; c < o.length; c++) (c + 1) % 2 == 1 ? 2 * parseInt(o[c]) < 9 ? s.push(2 * parseInt(o[c])) : i.push(2 * parseInt(o[c])) : u.push(o[c]);
        for (var l = new Array(), d = new Array(), p = 0; p < i.length; p++) l.push(parseInt(i[p]) % 10), 
        d.push(parseInt(i[p]) / 10);
        for (var g = 0, f = 0, h = 0, w = 0, y = 0, x = 0; x < s.length; x++) g += parseInt(s[x]);
        for (var m = 0; m < u.length; m++) f += parseInt(u[m]);
        for (var v = 0; v < l.length; v++) h += parseInt(l[v]), w += parseInt(d[v]);
        return y = parseInt(g) + parseInt(f) + parseInt(h) + parseInt(w), t == 10 - (parseInt(y) % 10 == 0 ? 10 : parseInt(y) % 10) || (e("请输入正确的银行卡号", "none"), 
        console.log("验证失败"), !1);
    },
    IdCardTest: function(n) {
        if (!/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(n)) return e("身份证格式不正确！", "none"), 
        !1;
        if (18 == n.length) {
            for (var t = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2), a = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2), o = 0, r = 0; r < 17; r++) o += n.substring(r, r + 1) * t[r];
            var s = o % 11, i = n.substring(17);
            return 2 == s ? "X" == i || "x" == i || (e("身份证号码错误!", "none"), !1) : i == a[s] || (e("身份证号码错误!", "none"), 
            !1);
        }
    },
    selectTimeHandler: function(e, n, t) {
        console.log(e);
        var a = new Date().getHours(), o = [], r = [];
        if (console.log(e, n, t), 0 === e && 0 === n) {
            for (o.push("现在"), s = a + 1; s < 24; s++) o.push(s + "点");
            return {
                hours: o
            };
        }
        if (0 === e && 0 !== n) {
            for (o.push("现在"), s = a + 1; s < 24; s++) o.push(s + "点");
            for (s = 0; s < 60; s += 10) r.push(s);
            return {
                hours: o,
                minute: r
            };
        }
        if (0 !== e) {
            for (s = 0; s < 24; s++) o.push(s + "点");
            for (var s = 0; s < 60; s += 10) r.push(s);
            return {
                hours: o,
                minute: r
            };
        }
    },
    userImg: "https://run.4hl.cn/addons/sd_drviing/core/public/WeChat/user/",
    driverImg: "https://run.4hl.cn/addons/sd_drviing/core/public/WeChat/driver/"
};